<?php if ($_SERVER["REQUEST_METHOD"] == "POST")
{
	//$q = intval($_GET['q']);

/*************************************************************************************************************************/
	$answer= $_POST['answer'];
	$truthvalue= $_POST['truthvalue'];
	$queryID= $_POST['queryid'];
/*************************************************************************************************************************/

	echo $answer." ".$truthvalue." ".$queryID;}
	// creates connection to database project

	$con = mysqli_connect('localhost','root','1234','PROJECT');

	$answerText =mysqli_real_escape_string($con,$answerText);// helps prevent database from attacks and misstyping

	// checks connection

	if (!$con)
  	{
  	die('Could not connect: ' . mysqli_error($con));
  	}

	//$result = mysqli_query($con,"select QUERY_ID from  ANSWER where ANSWER_ID=1;");// mysql query that get the question belonging to a specific answer

	//if($row = mysqli_fetch_array($result))// extract the row containing specified QUERY_ID
	//{
	//$queryId=$row['QUERY_ID'];	
	//echo $row['QUERY_ID'];
	//}

 	$insert = "INSERT INTO ANSWER (QUERY_ID, ANSWER_TEXT, TRUTH_VALUE) VALUES ('$queryID','$answer','$truthvalue')";// QUERY used to insert a new answer related to an answer

	if (!mysqli_query($con,$insert))// if query unsuccessfull return error message
 	 {
  	die('Error: ' . mysqli_error($con));
  	}
	

	if(1==0){}

	//$res2 = mysqli_query($con,"SELECT  QUERY, ANSWER_TEXT,  ANSWER_ID   FROM QUERY, ANSWER,QUIZ WHERE ANSWER.QUERY_ID = $qvar AND ANSWER.QUERY_ID =QUERY.QUERY_ID");

	//$result = mysqli_query($con,$sql);

	

	while($row = mysqli_fetch_array($result))
  	{
  	echo $row['ID']." ".$row['USERNAME']." ".$row['PASSWORD']."<br/>";
  	}
	echo "</table>";

	mysqli_close($con);
?>